package edu.pku.sei.transformation.editor.controller.commands.link;

import edu.pku.sei.transformation.editor.model.pattern.ILinkTemplate;
import edu.pku.sei.transformation.editor.model.pattern.INodeTemplate;

public class LinkTemplateCreateCommand
		extends
		AbstractLinkCreateCommand<ILinkTemplate, INodeTemplate, INodeTemplate> {
	public LinkTemplateCreateCommand(ILinkTemplate connection,
			INodeTemplate source) {
		super(connection, source);
	}

	@Override
	public void execute() {
		this.link.setSource(this.source);
		this.link.setTarget(this.target);
		this.source.getOutgoing().add(link);
		this.target.getIncoming().add(this.link);
		this.source.getPattern().getLinks().add(link);
	}

	@Override
	public void undo() {
		this.source.getOutgoing().remove(link);
		this.target.getIncoming().remove(this.link);
		this.source.getPattern().getLinks().remove(link);
	}
}
